import config
import random
from utils import *

def register():
	return RandomChoice()

class RandomChoice:
	def __init__(self):
		self.type = 'passive'
		self.help = \
'''重新排列：
	用法：
		*重排 (选择项1) (选择项2)...
	对给定的序列重新打乱顺序。'''

	def run(self, gum, msg):
		if not msg['type'] in ['FriendMessage', 'GroupMessage'] \
				or len(msg['messageChain']) <= 1 \
				or msg['messageChain'][1]['type'] != 'Plain' \
				or msg['messageChain'][1]['text'].split()[0] != '*重排':
			return

		splitted = msg['messageChain'][1]['text'].split()
		if random.random() < 0.1:
			autoReply('糖糖不想排……', gum)
		else:
			ls = splitted[1:]
			random.shuffle(ls)
			autoReply(' '.join(ls), gum)